﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Card.Web
{
    public partial class FindPW : BasePage
    {

        protected override void OnInit(EventArgs e)
        {
            this.btnNext.Click += new EventHandler(btnNext_Click);
            base.OnInit(e);
        }

        void btnNext_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtUserName.Text))
            {
                this.MessageBox("用户名不能为空！");
                return;
            }
            Entity.Users user = BLL.UsersManager.GetUserByUName(this.txtUserName.Text, this.Passport);
            if (user == null)
            {
                this.MessageBox("你输入的用户名不存在！");
                return;
            }

            BAF.Entity.LookupValue sysMail = Card.Common.LookUpCache.GetLookupValue(CONST.LOOKUP_TYPE.SYSTEM_CONFIG, CONST.SYSTEM_CONFIG_CODE.SYS_EMAIL);
            if (sysMail != null)
            {
                try
                {
                    string body = string.Format("感谢您使用{0}{1}找回密码功能，您的密码为：{2}",this.SiteName,this.SiteDomain,Card.Security.Utility.DecryptPassWord(user.Password));
                    Card.Utility.MailUtility.SendSmtpEMail(sysMail.Attribute2, sysMail.Value,this.SiteName, sysMail.Attribute1, user.Email, string.Format("找回密码_{0}", this.SiteName), body);
                }
                catch (Exception ex) 
                {
                    Log.Logger.Error(ex.ToString());                    
                }
            }

            this.input_uname.Visible = false;
            this.result.Visible = true;
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }


    }
}
